package chat.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;

import java.util.ArrayList;
import java.util.List;

import chat.model.RoomChatModel;
import model.RoomMessage;

/**
 * 群组消息
 * Created by 凯 on 2015/10/31.
 */
public class RoomMessageAdapter extends BaseAdapter {

    List<RoomMessage> roomMessages = new ArrayList<RoomMessage>();

    RoomChatModel roomChatModel = new RoomChatModel();

    public void setRoomMessages(List<RoomMessage> roomMessages) {
        this.roomMessages = roomMessages;
    }

    public void setRoomChatModel(RoomChatModel roomChatModel) {
        this.roomChatModel = roomChatModel;
    }

    @Override
    public int getCount() {
        return roomMessages.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RoomMessage roomMessage = roomMessages.get(position);


        if (roomMessage.getUser_ID().equals(MyApplication.getOwnUser().getUser_ID()))
        {
            convertView = View.inflate(MyApplication.share(), R.layout.item_right_groupmessage,null);
        }
        else
        {
            convertView = View.inflate(MyApplication.share(),R.layout.item_left_groupmessage,null);
        }

        TextView tv_time = (TextView) convertView.findViewById(R.id.id_tv_time);
        TextView tv_message = (TextView) convertView.findViewById(R.id.id_tv_message);

        tv_time.setText(roomMessage.getRm_Time());
        tv_message.setText(roomMessage.getRm_Content());
        if (!roomMessage.getUser_ID().equals(MyApplication.getOwnUser().getUser_ID()))
        {
            TextView tv_fromName = (TextView) convertView.findViewById(R.id.id_tv_fromName);
            tv_fromName.setText(roomMessage.getUser_RealName());
        }
        return convertView;
    }

}
